package com.xh.audit.service.impl;

import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.xh.audit.entity.WorkPlanVersion;
import com.xh.audit.mapper.WorkPlanVersionMapper;
import com.xh.audit.service.WorkPlanVersionService;
import com.xh.common.R;
import org.springframework.stereotype.Service;

import static com.xh.audit.entity.table.WorkPlanVersionTableDef.WORK_PLAN_VERSION;


/**
 *  服务层实现。
 *
 * @author LHL
 * @since 2023-10-21
 */
@Service
public class WorkPlanVersionServiceImpl extends ServiceImpl<WorkPlanVersionMapper, WorkPlanVersion> implements WorkPlanVersionService {

	@Override
	public R<WorkPlanVersion> getLatestWorkPlanById(Integer id) {
		if (id == null) {
			return R.failed("id空的:" + id);
		}

		QueryWrapper queryWrapper1 = QueryWrapper.create()
				.where(WORK_PLAN_VERSION.GROUP_PLAN_ID.eq(id))
				.orderBy(WORK_PLAN_VERSION.VERSION.desc()).limit(1);

		WorkPlanVersion workPlanLatestVersion = this.getOne(queryWrapper1);
		if (workPlanLatestVersion == null) {
			return R.failed("workPlan不存在:" + id);
		}
		return R.success("workPlan查询成功", workPlanLatestVersion);
	}
}
